package com.bianguo.android.apushdemo.view.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.bianguo.android.apushdemo.presenter.impl.BasePresenter;

/**
 * Created by Administrator on 2017/8/14.
 */

public abstract class BaseMvpActivity<V, T extends BasePresenter<V>> extends AppCompatActivity {

    public T presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId());
        //initPresenter()是抽象方法，让view初始化自己的presenter
        presenter = initPresenter();
        //presenter和view的绑定
        presenter.attach((V)this);
        //initActtivity是抽象方法，让view完成自身各种控件的初始化
        initView(savedInstanceState);
    }

    @Override
    protected void onResume() {
        presenter.onResume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        presenter.detach();
        super.onDestroy();
    }

    public abstract int layoutId();
    // 实例化presenter
    public abstract T initPresenter();
    public abstract void initView(Bundle savedInstanceState);
}
